/** ==================================================================================== **/
/** 																					 **/
/** ==================================================================================== **/

angular.module('windowUtil',[]).service('windowManager', function() {
	var opnWnd = [];
	
    this.registerWindow = function (x) {
    	opnWnd.unshift(x);
    }
    
    this.deleteAllWindow = function (x) {
    	opnWnd.splice(0, opnWnd.length);
    }
    
    this.deleteWindow = function (x) {
    	var i = opnWnd.length;
        while(i--){
           if(opnWnd[i]["idwindow"] === x ){ 
        	   opnWnd.splice(i,1);
           }
        }
    	//opnWnd.pop(x);
    }
    this.getWindow = function () {
    	return opnWnd;
    }
    this.getWindowLength = function () {
    	return opnWnd.length;
    }
    this.getWindowById = function (x) {
    	var result = $.grep(opnWnd, function(e){ return e.idwindow == x; });
    	if(result.length > 0)
    		return result[0];
    }
    this.setAttribute = function (x,attr,value) {
    	var result = $.grep(opnWnd, function(e){ return e.idwindow == x; });
    	if(result.length > 0){
    		delete result[0][attr];
    		result[0][attr]=value;
    	}
    }
    this.getAttribute = function (x,attr,value) {
    	var result = $.grep(opnWnd, function(e){ return e.idwindow == x; });
    	if(result.length > 0)
    		return result[0][attr];
    }
    
    this.setAttributeToAll = function (attr,value) {
    	var i = opnWnd.length;
        while(i--){
           opnWnd[i][attr] = value;
        }
    }
    
    this.isOpen = function(x){
    	var bool = false;
    	var result = $.grep(opnWnd, function(e){ return e.idwindow == x; });
    	if(result.length > 0)
    		bool = true;
    	return bool;
    }
});